﻿package client;
import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;

import server.ResTakeOutInterface;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.security.interfaces.RSAKey;
import java.util.Date;

import client.Configuration;
import java.awt.Font;
import javax.swing.ImageIcon;
import java.awt.Color;


public class ResTakeOutInfoGUI extends JDialog {

	private JPanel contentPane;
	private JTextField textField;
	private JTextField textField_1;
	private JTextField textField_2;
	private JLabel lblNewLabel;
	
//	ResTakeOutInfo takeOutInfo=new ResTakeOutInfo();

	/**
	 * Launch the application.
	
		
		 public static void main(String[] args){
			 EventQueue.invokeLater(new Runnable(){
         public void run() {
				try {
					ResTakeOutInfoGUI frame = new ResTakeOutInfoGUI();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}				 	 
				
	});
	}
 */		

	/**
	 * Create the frame.
	 */
	public ResTakeOutInfoGUI() {
		setTitle("\u9001\u9910\u4FE1\u606F\u8F93\u5165");
		setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 387, 281);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel label = new JLabel("\u59D3\u540D");
		label.setFont(new Font("方正舒体", Font.PLAIN, 18));
		label.setBounds(37, 26, 54, 15);
		contentPane.add(label);
		
		textField = new JTextField();
		textField.setBounds(119, 25, 134, 21);
		contentPane.add(textField);
		textField.setColumns(10);
		
		JLabel label_1 = new JLabel("\u7535\u8BDD\u53F7\u7801");
		label_1.setForeground(new Color(255, 255, 255));
		label_1.setFont(new Font("方正舒体", Font.PLAIN, 18));
		label_1.setBounds(37, 76, 75, 15);
		contentPane.add(label_1);
		
		textField_1 = new JTextField();
		textField_1.setBounds(119, 75, 134, 21);
		contentPane.add(textField_1);
		textField_1.setColumns(10);
		
		JLabel label_2 = new JLabel("\u5730\u5740");
		label_2.setFont(new Font("方正舒体", Font.PLAIN, 18));
		label_2.setBounds(37, 130, 54, 15);
		contentPane.add(label_2);
		
		textField_2 = new JTextField();
		textField_2.setBounds(119, 129, 134, 21);
		contentPane.add(textField_2);
		textField_2.setColumns(10);
		
		JButton button = new JButton("\u67E5\u770B\u83DC\u5355");
		button.setFont(new Font("方正舒体", Font.PLAIN, 18));
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(textField.getText().isEmpty()==false&&textField_1.getText().isEmpty()==false&&
						textField_2.getText().isEmpty()==false)
				{

					
					Configuration config=new Configuration();
					String rmiAddress=config.getRmiAddress();
					try {
						ResTakeOutInterface takeOut = (ResTakeOutInterface) Naming.lookup(rmiAddress+"ResTakeOutInfo");
						Date day=new Date();
						
						int t=takeOut.addNewOrder1(textField.getText(), textField_1.getText(), textField_2.getText(), day);
						
						dispose();
						ResMenuGUI menu=new ResMenuGUI(2,t);
						menu.setModal(true);
						menu.setLocationRelativeTo(null);
						menu.setVisible(true);
						
					} catch (MalformedURLException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					} catch (RemoteException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					} catch (NotBoundException e1) {					
						e1.printStackTrace();
					}
					
				}
				else
				{
					JOptionPane.showMessageDialog(null, "您的信息填写有误，请重新填写！");
				}
			}
		});
		button.setBounds(119, 190, 134, 23);
		contentPane.add(button);
		
		lblNewLabel = new JLabel("New label");
		lblNewLabel.setIcon(new ImageIcon("src/client/images/1.png"));
		lblNewLabel.setBounds(0, 0, 369, 245);
		contentPane.add(lblNewLabel);
	}

}